
# ifndef __DFX_THREAD_H__
# define __DFX_THREAD_H__

# include "dfxCore.h"

namespace DFX
{
    class Thread;

    enum PRIORITY
    {
        PRIORITY_IDLE,
        PRIORITY_LOWEST,
        PRIORITY_LOW,
        PRIORITY_NORMAL,
        PRIORITY_HIGH,
        PRIORITY_HIGHEST,
        PRIORITY_TIME_CRITICAL,
        PRIORITY_MAX
    };

    class DFX_EXPORT Task
    {
    protected:

        Thread  *mThread;

    public:

        Task()
        {
        }

        virtual ~Task()
        {
        }

        Thread* GetThread() const
        {
            return mThread;
        }

        void SetThread(Thread *t)
        {
            mThread = t;
        }

        virtual void Run() = 0;
    };
    
    class DFX_EXPORT Thread
    {
    protected:

        volatile bool   mPendingExit;
        PRIORITY        mPriority;

    public:

        Thread(PRIORITY pri)
            : mPriority(pri),
            mPendingExit(false)
        {
        }

        virtual ~Thread()
        {
        }        

        bool IsPendingExit() const
        {
            return mPendingExit;
        }       

        PRIORITY GetPriority() const
        {
            return mPriority;
        }

        virtual UInt32 GetHandle() const = 0;

        virtual void Start(Task *t) = 0;
        virtual void Exit(bool wait = false) = 0;

    public:

        static void Sleep(UInt32 milliSeconds);
    };    
}

# endif